//
// StoreNuke.Net -  http://www.storenuke.net
// Copyright (c) 2005
// by Robert J Collins ( info@storenuke.net ) of WillowTree Software, Inc. ( http://www.willowtreesoftware.com )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace StoreNuke.StarterKit.Commerce {

    //*******************************************************
    //
    // CustomerDetails Class
    //
    // A simple data class that encapsulates details about
    // a particular customer inside the Commerce Starter Kit Customer
    // database.
    //
    //*******************************************************

    public class CustomerDetails {

		public string FullName;
		public string FirstName;
		public string LastName;
        public string Email;
		public string Password;
		public bool IsAdmin;
    }

    //*******************************************************
    //
    // CustomersDB Class
    //
    // Business/Data Logic Class that encapsulates all data
    // logic necessary to add/login/query customers within
    // the Commerce Starter Kit Customer database.
    //
    //*******************************************************

    public class CustomersDB {

        //*******************************************************
        //
        // CustomersDB.GetCustomerDetails() Method <a name="GetCustomerDetails"></a>
        //
        // The GetCustomerDetails method returns a CustomerDetails
        // struct that contains information about a specific
        // customer (name, email, password, etc).
        //
        // Other relevant sources:
        //     + <a href="CustomerDetail.htm" style="color:green">CustomerDetail Stored Procedure</a>
        //
        //*******************************************************

        public CustomerDetails GetCustomerDetails(String customerID) 
        {

            // Create Instance of Connection and Command Object
            SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlCommand myCommand = new SqlCommand("StoreNuke_CustomerDetail", myConnection);

            // Mark the Command as a SPROC
            myCommand.CommandType = CommandType.StoredProcedure;

            // Add Parameters to SPROC
            SqlParameter parameterCustomerID = new SqlParameter("@CustomerID", SqlDbType.Int, 4);
            parameterCustomerID.Value = Int32.Parse(customerID);
            myCommand.Parameters.Add(parameterCustomerID);

            SqlParameter parameterFirstName = new SqlParameter("@FirstName", SqlDbType.NVarChar, 50);
            parameterFirstName.Direction = ParameterDirection.Output;
			myCommand.Parameters.Add(parameterFirstName);

			SqlParameter parameterLastName = new SqlParameter("@LastName", SqlDbType.NVarChar, 50);
			parameterLastName.Direction = ParameterDirection.Output;
			myCommand.Parameters.Add(parameterLastName);

            SqlParameter parameterEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 50);
            parameterEmail.Direction = ParameterDirection.Output;
            myCommand.Parameters.Add(parameterEmail);

            SqlParameter parameterPassword = new SqlParameter("@Password", SqlDbType.NVarChar, 50);
            parameterPassword.Direction = ParameterDirection.Output;
			myCommand.Parameters.Add(parameterPassword);

			SqlParameter parameterIsAdmin = new SqlParameter("@IsAdmin", SqlDbType.Bit, 1);
			parameterIsAdmin.Direction = ParameterDirection.Output;
			myCommand.Parameters.Add(parameterIsAdmin);

            myConnection.Open();
            myCommand.ExecuteNonQuery();
            myConnection.Close();

            // Create CustomerDetails Struct
            CustomerDetails myCustomerDetails = new CustomerDetails();

            // Populate Struct using Output Params from SPROC 
			myCustomerDetails.FirstName = (string)parameterFirstName.Value;
			myCustomerDetails.LastName = (string)parameterLastName.Value;
            myCustomerDetails.Password = (string)parameterPassword.Value;
			myCustomerDetails.Email = (string)parameterEmail.Value;
			myCustomerDetails.IsAdmin = (bool)parameterIsAdmin.Value;
			myCustomerDetails.FullName = myCustomerDetails.FirstName + " " + myCustomerDetails.LastName;

            return myCustomerDetails;
        }

        //*******************************************************
        //
        // CustomersDB.AddCustomer() Method <a name="AddCustomer"></a>
        //
        // The AddCustomer method inserts a new customer record
        // into the customers database.  A unique "CustomerId"
        // key is then returned from the method.  This can be
        // used later to place orders, track shopping carts,
        // etc within the ecommerce system.
        //
        // Other relevant sources:
        //     + <a href="CustomerAdd.htm" style="color:green">CustomerAdd Stored Procedure</a>
        //
        //*******************************************************

        public String AddCustomer(string firstName, string lastName, string email, string password, bool isAdmin) 
        {

            // Create Instance of Connection and Command Object
            SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlCommand myCommand = new SqlCommand("StoreNuke_CustomerAdd", myConnection);

            // Mark the Command as a SPROC
            myCommand.CommandType = CommandType.StoredProcedure;

            // Add Parameters to SPROC
            SqlParameter parameterFirstName = new SqlParameter("@FirstName", SqlDbType.NVarChar, 50);
            parameterFirstName.Value = firstName;
			myCommand.Parameters.Add(parameterFirstName);

			SqlParameter parameterLastName = new SqlParameter("@LastName", SqlDbType.NVarChar, 50);
			parameterLastName.Value = lastName;
			myCommand.Parameters.Add(parameterLastName);

            SqlParameter parameterEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 50);
            parameterEmail.Value = email;
            myCommand.Parameters.Add(parameterEmail);

            SqlParameter parameterPassword = new SqlParameter("@Password", SqlDbType.NVarChar, 50);
            parameterPassword.Value = password;
            myCommand.Parameters.Add(parameterPassword);

			SqlParameter parameterIsAdmin = new SqlParameter("@IsAdmin", SqlDbType.Bit, 1);
			parameterIsAdmin.Value = isAdmin;
			myCommand.Parameters.Add(parameterIsAdmin);

            SqlParameter parameterCustomerID = new SqlParameter("@CustomerID", SqlDbType.Int, 4);
            parameterCustomerID.Direction = ParameterDirection.Output;
            myCommand.Parameters.Add(parameterCustomerID);

            try {
                myConnection.Open();
                myCommand.ExecuteNonQuery();
                myConnection.Close();

                // Calculate the CustomerID using Output Param from SPROC
                int customerId = (int)parameterCustomerID.Value;

                return customerId.ToString();
            }
            catch {
                return String.Empty;
            }
		}

		//*******************************************************
		//
		// CustomersDB.UpdateCustomer() Method <a name="UpdateCustomer"></a>
		//
		// The UpdateCustomer method inserts a new customer record
		// into the customers database.  A unique "CustomerId"
		// key is then returned from the method.  This can be
		// used later to place orders, track shopping carts,
		// etc within the ecommerce system.
		//
		// Other relevant sources:
		//     + <a href="UpdateCustomer.htm" style="color:green">CustomerUpdate Stored Procedure</a>
		//
		//*******************************************************

		public bool UpdateCustomer(int CustomerID, string firstName, string lastName, string email, string password, bool isAdmin) 
		{

			// Create Instance of Connection and Command Object
			SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
			SqlCommand myCommand = new SqlCommand("StoreNuke_CustomerUpdate", myConnection);

			// Mark the Command as a SPROC
			myCommand.CommandType = CommandType.StoredProcedure;

			// Add Parameters to SPROC
			SqlParameter parameterCustomerID = new SqlParameter("@CustomerID", SqlDbType.Int, 4);
			parameterCustomerID.Value = CustomerID;
			myCommand.Parameters.Add(parameterCustomerID);

			SqlParameter parameterFirstName = new SqlParameter("@FirstName", SqlDbType.NVarChar, 50);
			parameterFirstName.Value = firstName;
			myCommand.Parameters.Add(parameterFirstName);

			SqlParameter parameterLastName = new SqlParameter("@LastName", SqlDbType.NVarChar, 50);
			parameterLastName.Value = lastName;
			myCommand.Parameters.Add(parameterLastName);

			SqlParameter parameterEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 50);
			parameterEmail.Value = email;
			myCommand.Parameters.Add(parameterEmail);

			SqlParameter parameterPassword = new SqlParameter("@Password", SqlDbType.NVarChar, 50);
			parameterPassword.Value = password;
			myCommand.Parameters.Add(parameterPassword);

			SqlParameter parameterIsAdmin = new SqlParameter("@IsAdmin", SqlDbType.Bit, 1);
			parameterIsAdmin.Value = isAdmin;
			myCommand.Parameters.Add(parameterIsAdmin);

			try 
			{
				myConnection.Open();
				myCommand.ExecuteNonQuery();
				myConnection.Close();

				return true;
			}
			catch 
			{
				return false;
			}
		}

        //*******************************************************
        //
        // CustomersDB.Login() Method <a name="Login"></a>
        //
        // The Login method validates a email/password pair
        // against credentials stored in the customers database.
        // If the email/password pair is valid, the method returns
        // the "CustomerId" number of the customer.  Otherwise
        // it will throw an exception.
        //
        // Other relevant sources:
        //     + <a href="CustomerLogin.htm" style="color:green">CustomerLogin Stored Procedure</a>
        //
        //*******************************************************

        public String Login(string email, string password) 
        {

            // Create Instance of Connection and Command Object
            SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlCommand myCommand = new SqlCommand("StoreNuke_CustomerLogin", myConnection);

            // Mark the Command as a SPROC
            myCommand.CommandType = CommandType.StoredProcedure;

            // Add Parameters to SPROC
            SqlParameter parameterEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 50);
            parameterEmail.Value = email;
            myCommand.Parameters.Add(parameterEmail);

            SqlParameter parameterPassword = new SqlParameter("@Password", SqlDbType.NVarChar, 50);
            parameterPassword.Value = password;
            myCommand.Parameters.Add(parameterPassword);

            SqlParameter parameterCustomerID = new SqlParameter("@CustomerID", SqlDbType.Int, 4);
            parameterCustomerID.Direction = ParameterDirection.Output;
            myCommand.Parameters.Add(parameterCustomerID);

            // Open the connection and execute the Command
            myConnection.Open();
            myCommand.ExecuteNonQuery();
            myConnection.Close();

            int customerId = (int)(parameterCustomerID.Value);

            if (customerId == 0) {
                return null;
            }
            else {
                return customerId.ToString();
            }
        }

		public void AddCustomerAddress(int customerID, string address1, string address2, string attn, string city, string region, string country, string postalCode, string phone1, string phone2, bool primaryAddress) 
		{
			// Create Instance of Connection and Command Object
			SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
			SqlCommand myCommand = new SqlCommand("StoreNuke_AddCustomerAddress", myConnection);

			// Mark the Command as a SPROC
			myCommand.CommandType = CommandType.StoredProcedure;

			// Add Parameters to SPROC
			SqlParameter parameterCustomerID = new SqlParameter("@CustomerID", SqlDbType.Int, 4);
			parameterCustomerID.Value = customerID;
			myCommand.Parameters.Add(parameterCustomerID);
	
				SqlParameter parameterAddress1 = new SqlParameter("@Address1", SqlDbType.NVarChar, 50);
			parameterAddress1.Value = address1;
			myCommand.Parameters.Add(parameterAddress1);

			SqlParameter parameterAddress2 = new SqlParameter("@Address2", SqlDbType.NVarChar, 50);
			parameterAddress2.Value = address2;
			myCommand.Parameters.Add(parameterAddress2);

			SqlParameter parameterATTN = new SqlParameter("@ATTN", SqlDbType.NVarChar, 50);
			parameterATTN.Value = attn;
			myCommand.Parameters.Add(parameterATTN);

			SqlParameter parameterCity = new SqlParameter("@City", SqlDbType.NVarChar, 20);
			parameterCity.Value = city;
			myCommand.Parameters.Add(parameterCity);
	
			SqlParameter parameterRegion = new SqlParameter("@RegionCode", SqlDbType.NVarChar, 2);
			parameterRegion.Value = region;
			myCommand.Parameters.Add(parameterRegion);

			SqlParameter parameterCountry = new SqlParameter("@CountryCode", SqlDbType.NVarChar, 2);
			parameterCountry.Value = country;
			myCommand.Parameters.Add(parameterCountry);

			SqlParameter parameterPostalCode = new SqlParameter("@PostalCode", SqlDbType.NVarChar, 10);
			parameterPostalCode.Value = postalCode;
			myCommand.Parameters.Add(parameterPostalCode);

			SqlParameter parameterPhone1 = new SqlParameter("@Phone1", SqlDbType.NVarChar, 20);
			parameterPhone1.Value = phone1;
			myCommand.Parameters.Add(parameterPhone1);

			SqlParameter parameterPhone2 = new SqlParameter("@Phone2", SqlDbType.NVarChar, 20);
			parameterPhone2.Value = phone2;
			myCommand.Parameters.Add(parameterPhone2);

			SqlParameter parameterPrimaryAddress = new SqlParameter("@PrimaryAddress", SqlDbType.Bit, 1);
			parameterPrimaryAddress.Value = primaryAddress;
			myCommand.Parameters.Add(parameterPrimaryAddress);

			myConnection.Open();
			myCommand.ExecuteNonQuery();
			myConnection.Close();
		}

		public SqlDataReader GetAllAddresses(int customerID) 
		{

			// Create Instance of Connection and Command Object
			SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
			SqlCommand myCommand = new SqlCommand("StoreNuke_GetAllAddresses", myConnection);

			// Mark the Command as a SPROC
			myCommand.CommandType = CommandType.StoredProcedure;

			SqlParameter parameterCustomerID = new SqlParameter("@CustomerID", SqlDbType.NVarChar, 20);
			parameterCustomerID.Value = customerID;
			myCommand.Parameters.Add(parameterCustomerID);

			// Execute the command
			myConnection.Open();
			SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

			// Return the datareader result
			return result;
		}

		public SqlDataReader GetSingleAddresses(int addressID) 
		{

			// Create Instance of Connection and Command Object
			SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
			SqlCommand myCommand = new SqlCommand("StoreNuke_GetSingleAddresses", myConnection);

			// Mark the Command as a SPROC
			myCommand.CommandType = CommandType.StoredProcedure;

			SqlParameter parameterAddressID = new SqlParameter("@AddressID", SqlDbType.NVarChar, 20);
			parameterAddressID .Value = addressID;
			myCommand.Parameters.Add(parameterAddressID );

			// Execute the command
			myConnection.Open();
			SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

			// Return the datareader result
			return result;
		}

		public bool CheckPrimaryAddress(int customerID, int addressID)
		{
			SqlDataReader dr = GetPrimaryAddress(customerID);
			bool found = false;
			if(dr.Read())
			{
				if((int)dr["AddressID"] == addressID)
				{
					found = true;
				}
				else
				{
					found = false;
				}
			}
			dr.Close();
			return found;
		}

		public SqlDataReader GetPrimaryAddress(int customerID) 
		{

			// Create Instance of Connection and Command Object
			SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
			SqlCommand myCommand = new SqlCommand("StoreNuke_GetPrimaryAddress", myConnection);

			// Mark the Command as a SPROC
			myCommand.CommandType = CommandType.StoredProcedure;

			SqlParameter parameterCustomerID = new SqlParameter("@CustomerID", SqlDbType.NVarChar, 20);
			parameterCustomerID.Value = customerID;
			myCommand.Parameters.Add(parameterCustomerID);

			// Execute the command
			myConnection.Open();
			SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

			// Return the datareader result
			return result;
		}

		public void UpdateCustomerAddress(int addressID, string address1, string address2, string attn, string city, string region, string country, string postalCode, string phone1, string phone2, bool primaryAddress) 
		{
			// Create Instance of Connection and Command Object
			SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
			SqlCommand myCommand = new SqlCommand("StoreNuke_UpdateCustomerAddress", myConnection);

			// Mark the Command as a SPROC
			myCommand.CommandType = CommandType.StoredProcedure;

			// Add Parameters to SPROC
			SqlParameter parameterAddressID = new SqlParameter("@AddressID", SqlDbType.Int, 4);
			parameterAddressID.Value = addressID;
			myCommand.Parameters.Add(parameterAddressID);
	
			SqlParameter parameterAddress1 = new SqlParameter("@Address1", SqlDbType.NVarChar, 50);
			parameterAddress1.Value = address1;
			myCommand.Parameters.Add(parameterAddress1);

			SqlParameter parameterAddress2 = new SqlParameter("@Address2", SqlDbType.NVarChar, 50);
			parameterAddress2.Value = address2;
			myCommand.Parameters.Add(parameterAddress2);

			SqlParameter parameterATTN = new SqlParameter("@ATTN", SqlDbType.NVarChar, 50);
			parameterATTN.Value = attn;
			myCommand.Parameters.Add(parameterATTN);

			SqlParameter parameterCity = new SqlParameter("@City", SqlDbType.NVarChar, 20);
			parameterCity.Value = city;
			myCommand.Parameters.Add(parameterCity);
	
			SqlParameter parameterRegion = new SqlParameter("@RegionCode", SqlDbType.NVarChar, 2);
			parameterRegion.Value = region;
			myCommand.Parameters.Add(parameterRegion);

			SqlParameter parameterCountry = new SqlParameter("@CountryCode", SqlDbType.NVarChar, 2);
			parameterCountry.Value = country;
			myCommand.Parameters.Add(parameterCountry);

			SqlParameter parameterPostalCode = new SqlParameter("@PostalCode", SqlDbType.NVarChar, 10);
			parameterPostalCode.Value = postalCode;
			myCommand.Parameters.Add(parameterPostalCode);

			SqlParameter parameterPhone1 = new SqlParameter("@Phone1", SqlDbType.NVarChar, 20);
			parameterPhone1.Value = phone1;
			myCommand.Parameters.Add(parameterPhone1);

			SqlParameter parameterPhone2 = new SqlParameter("@Phone2", SqlDbType.NVarChar, 20);
			parameterPhone2.Value = phone2;
			myCommand.Parameters.Add(parameterPhone2);

			SqlParameter parameterPrimaryAddress = new SqlParameter("@PrimaryAddress", SqlDbType.Bit, 1);
			parameterPrimaryAddress.Value = primaryAddress;
			myCommand.Parameters.Add(parameterPrimaryAddress);

			myConnection.Open();
			myCommand.ExecuteNonQuery();
			myConnection.Close();
		}

		public void UpdatePrimaryCustomerAddress(int CustomerID, string address1, string address2, string attn, string city, string region, string country, string postalCode, string phone1, string phone2) 
		{
			// Create Instance of Connection and Command Object
			SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
			SqlCommand myCommand = new SqlCommand("StoreNuke_UpdatePrimaryCustomerAddress", myConnection);

			// Mark the Command as a SPROC
			myCommand.CommandType = CommandType.StoredProcedure;

			// Add Parameters to SPROC
			SqlParameter parameterCustomerID = new SqlParameter("@CustomerID", SqlDbType.Int, 4);
			parameterCustomerID.Value = CustomerID;
			myCommand.Parameters.Add(parameterCustomerID);
	
			SqlParameter parameterAddress1 = new SqlParameter("@Address1", SqlDbType.NVarChar, 50);
			parameterAddress1.Value = address1;
			myCommand.Parameters.Add(parameterAddress1);

			SqlParameter parameterAddress2 = new SqlParameter("@Address2", SqlDbType.NVarChar, 50);
			parameterAddress2.Value = address2;
			myCommand.Parameters.Add(parameterAddress2);

			SqlParameter parameterATTN = new SqlParameter("@ATTN", SqlDbType.NVarChar, 50);
			parameterATTN.Value = attn;
			myCommand.Parameters.Add(parameterATTN);

			SqlParameter parameterCity = new SqlParameter("@City", SqlDbType.NVarChar, 20);
			parameterCity.Value = city;
			myCommand.Parameters.Add(parameterCity);
	
			SqlParameter parameterRegion = new SqlParameter("@RegionCode", SqlDbType.NVarChar, 2);
			parameterRegion.Value = region;
			myCommand.Parameters.Add(parameterRegion);

			SqlParameter parameterCountry = new SqlParameter("@CountryCode", SqlDbType.NVarChar, 2);
			parameterCountry.Value = country;
			myCommand.Parameters.Add(parameterCountry);

			SqlParameter parameterPostalCode = new SqlParameter("@PostalCode", SqlDbType.NVarChar, 10);
			parameterPostalCode.Value = postalCode;
			myCommand.Parameters.Add(parameterPostalCode);

			SqlParameter parameterPhone1 = new SqlParameter("@Phone1", SqlDbType.NVarChar, 20);
			parameterPhone1.Value = phone1;
			myCommand.Parameters.Add(parameterPhone1);

			SqlParameter parameterPhone2 = new SqlParameter("@Phone2", SqlDbType.NVarChar, 20);
			parameterPhone2.Value = phone2;
			myCommand.Parameters.Add(parameterPhone2);

			myConnection.Open();
			myCommand.ExecuteNonQuery();
			myConnection.Close();
		}

		public SqlDataReader GetRegionCode(string country) 
		{

			// Create Instance of Connection and Command Object
			SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
			SqlCommand myCommand = new SqlCommand("StoreNuke_GetRegionCode", myConnection);

			// Mark the Command as a SPROC
			myCommand.CommandType = CommandType.StoredProcedure;

			SqlParameter parameterCountry = new SqlParameter("@Country", SqlDbType.NVarChar, 2);
			parameterCountry.Value = country;
			myCommand.Parameters.Add(parameterCountry);

			// Execute the command
			myConnection.Open();
			SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

			// Return the datareader result
			return result;
		}

		public SqlDataReader GetCountryCode() 
		{

			// Create Instance of Connection and Command Object
			SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
			SqlCommand myCommand = new SqlCommand("StoreNuke_GetCountryCode", myConnection);

			// Mark the Command as a SPROC
			myCommand.CommandType = CommandType.StoredProcedure;

			// Execute the command
			myConnection.Open();
			SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

			// Return the datareader result
			return result;
		}

		public SqlDataReader GetAllCustomers() 
		{

			// Create Instance of Connection and Command Object
			SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
			SqlCommand myCommand = new SqlCommand("StoreNuke_GetAllCustomers", myConnection);

			// Mark the Command as a SPROC
			myCommand.CommandType = CommandType.StoredProcedure;

			// Execute the command
			myConnection.Open();
			SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

			// Return the datareader result
			return result;
		}
    }
}

